<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 传统的面向对象 继承
        class MovieCollection extends Array{
            constructor(name,...items){//reset
                super(...items);// 父类的构造函数 展开运算符
                this.name=name;
            }
            add(movie){
                this.push(movie);
            }
            topRated(limit=10){//默认值
                return this.sort((a,b)=>b.starts-a.starts).slice(0,limit);
            }
        }
        const movies=new MovieCollection(`wes\'s Fav Movies`,
          {name:'Bee Movie',starts:6} ,
          {name:'star wars trek',starts:1} ,
          {name:'virigin suicides',starts:7} ,
          {name:'king of the road',starts:8} 

        )
        movies.add({name:'zz',starts:9});
        console.log(movies.topRated(3));
    </script>
</body>
</html>